package com.burgstaller.aGTD.utils;

import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CursorAdapter;

public class CheckboxTaskCursorAdapter extends CursorAdapter {
	private int m_completedColumnIndex;
	private int m_titleColumnIndex;
	
	public CheckboxTaskCursorAdapter(Cursor c, Context context, 
			int completedColumnIndex, int titleColumnIndex, 
			Drawable normalIcon, Drawable completedIcon) {
		super(c, context);
		m_completedColumnIndex = completedColumnIndex;
		m_titleColumnIndex = titleColumnIndex;
	}
	
	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		CheckBox boxView = (CheckBox) view;
		boxView.setText(cursor.getString(m_titleColumnIndex));
		int completed = cursor.getInt(m_completedColumnIndex);
		boxView.setChecked(completed != 0);
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup viewgroup) {
        CheckBox result = new CheckBox(mContext);
        return result;
	}

}
